//
//  CYYSFilterView.m
//  CreditAddressBook
//
//  Created by LE on 15/12/28.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "CYYSFilterView.h"
#import "BEMCheckBox.h"
#import "MTCityViewController.h"
#import "CYNavigationVController.h"

@interface CYYSFilterView ()<BEMCheckBoxDelegate>

@property (weak, nonatomic) IBOutlet BEMCheckBox *checkBoxMan;
@property (weak, nonatomic) IBOutlet BEMCheckBox *checkBoxFemale;
@property (weak, nonatomic) IBOutlet UILabel *areaLabel;

@property(nonatomic, weak) BEMCheckBox *selectedCheckBox;
@end

@implementation CYYSFilterView

- (void)awakeFromNib {
    self.checkBoxMan.onAnimationType = BEMAnimationTypeBounce;
    self.checkBoxMan.offAnimationType = BEMAnimationTypeBounce;
    self.checkBoxFemale.onAnimationType = BEMAnimationTypeBounce;
    self.checkBoxFemale.offAnimationType = BEMAnimationTypeBounce;
    self.checkBoxMan.tag = CYSexMan;
    self.checkBoxFemale.tag = CYSexFemale;
    
    self.checkBoxFemale.delegate = self;
    self.checkBoxMan.delegate = self;
    
    self.checkBoxMan.on = YES;
    self.selectedCheckBox = self.checkBoxMan;
    self.selectedSex = CYSexMan;
}

- (void)didTapCheckBox:(BEMCheckBox*)checkBox {
    if (checkBox.on) {
        self.selectedCheckBox.on = NO;
        self.selectedCheckBox = checkBox;
        self.selectedSex = checkBox.tag;
    } else {
        checkBox.on = YES;
    }
}

- (IBAction)selectCityBtn:(UIButton *)sender {
    MTCityViewController *city = [[MTCityViewController alloc] init];
    CYNavigationVController *nav = [[CYNavigationVController alloc] initWithRootViewController:city];
    nav.modalPresentationStyle = UIModalPresentationFormSheet;
    CYWeakObject(weakself, self);
    [city selectedCity:^(NSString *city) {
        weakself.selectedCity = city;
        weakself.areaLabel.text = city;
        weakself.areaLabel.textColor = [UIColor blackColor];
    }];
    [self.controller presentViewController:nav animated:YES completion:nil];
}

- (void)setFrame:(CGRect)frame {
    frame.size.height = 100;
    [super setFrame:frame];
}
@end
